<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 云淡风轻(97139915@qq.com)
// +----------------------------------------------------------------------


class SuppliersCateAction extends CommonAction{
	//增
	public function add()
	{
		$new_sort = D(MODULE_NAME)-> max("sort") + 1;
		$this->assign('new_sort',$new_sort);
		$this->display();
	}
	
function insert() {
		//B('FilterString');
		$name=$this->getActionName();
		$model = D ($name);
		
		if (false === $data = $model->create ()) {
			$this->error ( $model->getError () );
		}

		$upload_list = $this->uploadFile(0,"public");
		if($upload_list)
		{	

			foreach($upload_list as $upload_item)
			{
				if($upload_item['key']=="icon")
				{
					$data['icon'] = $upload_item['recpath'].$upload_item['savename'];
				}
			
			}

		}
		
		$list=$model->add ($data);
		if ($list!==false) { //保存成功
			$this->saveLog(1,$list);
//			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success (L('ADD_SUCCESS'));
		} else {
			//失败提示
			$this->saveLog(0,$list);
			$this->error (L('ADD_FAILED'));
		}
	}
	function update() {
		//B('FilterString');
		$name=$this->getActionName();
		$model = D ( $name );
		if (false === $data = $model->create ()) {
			$this->error ( $model->getError () );
		}
		$coupon = M("SuppliersCate")->getById($data['id']);
				
		
		$upload_list = $this->uploadFile(0,"public");
		if($upload_list)
		{	
			foreach($upload_list as $upload_item)
			{
				if($upload_item['key']=="icon")
				{
					@unlink(getcwd().$coupon['icon']);
					$data['icon'] = $upload_item['recpath'].$upload_item['savename'];
				}
			
			}
		}
		
		$list=$model->save ($data);
		if (false !== $list) {
			//成功提示
			$this->saveLog(1);
//			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success (L('EDIT_SUCCESS'));
		} else {
			//错误提示
			$this->saveLog(0);
			$this->error (L('EDIT_FAILED'));
		}
	}
}
?>